package com.ks.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ks.common.PageResult;
import com.ks.dto.PageQueryDTO;
import com.ks.entity.Indicator;
import com.ks.mapper.IndicatorMapper;
import com.ks.service.IndicatorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class IndicatorServiceImpl extends ServiceImpl<IndicatorMapper, Indicator> implements IndicatorService {

    @Autowired
    private IndicatorMapper indicatorMapper;

    @Override
    public PageResult pageIndicator(PageQueryDTO pageQueryDTO) {
        IPage page = new Page(pageQueryDTO.getPage(), pageQueryDTO.getPageSize());
        LambdaQueryWrapper<Indicator> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        page = page(page, lambdaQueryWrapper);
        PageResult pageResult = PageResult.builder()
                .total(page.getTotal())
                .records(page.getRecords())
                .build();
        return pageResult;
    }

    @Override
    public void addIndicator(Indicator indicator) {
        indicatorMapper.insert(indicator);
    }

    @Override
    public void deleteIndicator(Integer id) {
        indicatorMapper.deleteById(id);
    }

    @Override
    public void updateIndicator(Indicator indicator) {
        indicatorMapper.updateById(indicator);
    }

    @Override
    public String[] getNameList() {
        return indicatorMapper.getAllName();
    }
}
